/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JCFrameReproductor.java
 *
 * Created on 11-feb-2011, 14:27:04
 */

package JC.skin.vista;

import JC.utileria.Archivos;
import JC.utileria.Filtro;
import JC.utileria.Reproductor;
import JC.utileria.Tiempo;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusListener;
import java.io.File;
import java.util.LinkedList;
import java.util.Random;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.table.DefaultTableModel;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.skin.ChallengerDeepSkin;
/**
 *
 * @author cabarcas
 */
public class JCFrameReproductor extends javax.swing.JFrame implements ControllerListener{

    /** Creates new form JCFrameReproductor */
    private int playcliked,pauseclicked,stopclicked,previusclicked,nextclicked,col,fila;
    private Thread t,t2,t3,t4,t5,t6,time,time2;
    private Timer listo,tr;
    private LinkedList<File> list;
    private File f;
    private Reproductor r;
    private int miliseg,segundo,minutos,horas;

    public JCFrameReproductor() {
        stopclicked=500;
        r=new Reproductor(this);
        r.setControl(progreso);
        initComponents();
        lista_reproduccion.setCellSelectionEnabled(true);
        lista_reproduccion.setColumnSelectionInterval(0, 0);
        
        tiempoReproduccion.setText("00:00:00");
//        archivos.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
        archivos.setFileFilter(Filtro.filtrar("mp3 & wav", "wav", "MP3"));

        tr=new Timer(1000, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
//                progreso.setValue(miliseg++);
                controllerUpdate(new ControllerEvent(r.getPlayer()));
                segundo+=1;

                if(segundo==60){
                    minutos+=1;
                    segundo=0;
                }
                if(minutos==60){
                    minutos=0;
                    horas+=1;
                }
                tiempoReproduccion.setText(digito(horas)+":"+digito(minutos)+":"+digito(segundo));
            }
        });
        t=new Thread(new Runnable() {

            public void run() {
                animacion();
            }
        },"ejecucion");
        t2=new Thread(new Runnable() {

            public void run() {
                r.play();
                tr.start();
            }
        },"ejecucion");
        t3=new Thread(new Runnable() {

            public void run() {
                r.stop();
            }
        },"ejecucion");
        t4=new Thread(new Runnable() {

            public void run() {
                r.pause();
            }
        },"ejecucion");
        t5=new Thread(new Runnable() {

            public void run() {
                int numero=azar();
                animacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jc/skin/imagenes/disco_"+numero+".JPG")));
            }
        },"ejecucion");

        t6=new Thread(new Runnable() {
            public void run() {
                r.abrirContenidoMM(f);
                r.init(f.getAbsolutePath(),f);
            }
        },"ejecucion");
        
        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        archivos = new javax.swing.JFileChooser();
        jLabel1 = new javax.swing.JLabel();
        panel1 = new javax.swing.JPanel();
        pause = new javax.swing.JLabel();
        play = new javax.swing.JLabel();
        previus = new javax.swing.JLabel();
        stop = new javax.swing.JLabel();
        next = new javax.swing.JLabel();
        animacion = new javax.swing.JLabel();
        open = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        lista_reproduccion = new javax.swing.JTable();
        jSeparator1 = new javax.swing.JSeparator();
        tiempoReproduccion = new javax.swing.JLabel();
        progreso = new javax.swing.JSlider();
        btnRandom = new javax.swing.JToggleButton();

        archivos.setCurrentDirectory(new java.io.File("C:\\Documents and Settings\\cabarcas\\Escritorio"));
        archivos.setDialogType(javax.swing.JFileChooser.CUSTOM_DIALOG);
        archivos.setFileSelectionMode(javax.swing.JFileChooser.FILES_AND_DIRECTORIES);
        archivos.setAutoscrolls(true);
        archivos.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);

        jLabel1.setText("jLabel1");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setResizable(false);

        panel1.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        panel1.setAutoscrolls(true);

        pause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/pausa/pause_1.png"))); // NOI18N
        pause.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                pauseMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                pauseMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                pauseMouseExited(evt);
            }
        });

        play.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/play/play_1.png"))); // NOI18N
        play.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                playMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                playMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                playMouseExited(evt);
            }
        });

        previus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/previo/previus_1.png"))); // NOI18N
        previus.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                previusMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                previusMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                previusMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                previusMousePressed(evt);
            }
        });

        stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/stop/stop_4.png"))); // NOI18N
        stop.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                stopMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                stopMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                stopMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                stopMousePressed(evt);
            }
        });

        next.setBackground(new java.awt.Color(0, 0, 0));
        next.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/siguiente/next_1.png"))); // NOI18N
        next.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                nextMouseClicked(evt);
            }
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                nextMouseEntered(evt);
            }
            public void mouseExited(java.awt.event.MouseEvent evt) {
                nextMouseExited(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                nextMousePressed(evt);
            }
        });

        javax.swing.GroupLayout panel1Layout = new javax.swing.GroupLayout(panel1);
        panel1.setLayout(panel1Layout);
        panel1Layout.setHorizontalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(previus, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(pause)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(play)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(stop)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(next)
                .addGap(16, 16, 16))
        );
        panel1Layout.setVerticalGroup(
            panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(next, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(stop, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(play, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(pause, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE)
                    .addComponent(previus, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 32, Short.MAX_VALUE))
                .addContainerGap())
        );

        animacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/imagenes/disco_1.gif"))); // NOI18N

        open.setBackground(new java.awt.Color(204, 102, 0));
        open.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/open/open_1.png"))); // NOI18N
        open.setAutoscrolls(true);
        open.setFocusCycleRoot(true);
        open.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                openMouseClicked(evt);
            }
        });

        lista_reproduccion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "..::LISTA DE REPRODUCCION::.."
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        lista_reproduccion.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                lista_reproduccionMouseClicked(evt);
            }
        });
        jScrollPane1.setViewportView(lista_reproduccion);
        lista_reproduccion.getColumnModel().getColumn(0).setResizable(false);

        progreso.setBackground(new java.awt.Color(0, 0, 0));
        progreso.setForeground(new java.awt.Color(204, 0, 0));
        progreso.setPaintTicks(true);
        progreso.setValue(0);

        btnRandom.setBackground(new java.awt.Color(204, 0, 0));
        btnRandom.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/imagenes/random.png"))); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, 0, 0, Short.MAX_VALUE)
                    .addComponent(animacion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(open)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 97, Short.MAX_VALUE)
                                .addComponent(tiempoReproduccion, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(btnRandom, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
                    .addComponent(progreso, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(animacion)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(panel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(17, 17, 17)
                                    .addComponent(open)))
                            .addComponent(tiempoReproduccion, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(btnRandom, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(progreso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 123, Short.MAX_VALUE)
                .addContainerGap())
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-428)/2, (screenSize.height-597)/2, 428, 597);
    }// </editor-fold>//GEN-END:initComponents

    private void playMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playMouseEntered
        // TODO add your handling code here:
        if(playcliked!=500)
            play.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/play/play_3.png")));

    }//GEN-LAST:event_playMouseEntered

    private void playMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playMouseExited
        // TODO add your handling code here:
        if(playcliked!=500)
            play.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/play/play_1.png")));
    }//GEN-LAST:event_playMouseExited

    private void playMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_playMouseClicked
        // TODO add your handling code here:
        playcliked=evt.MOUSE_CLICKED;
        pauseclicked=0;
        stopclicked=0;
        titulo();

        play.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/play/play_2.png")));
        stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/stop/stop_1.png")));
        pause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/pausa/pause_1.png")));
        t.run();
        if(r.getPlayer()!=null)
            t2.run();
        
       
    }//GEN-LAST:event_playMouseClicked

    private void pauseMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMouseClicked
        // TODO add your handling code here:
        titulo();
        tr.stop();
        pauseclicked=evt.MOUSE_CLICKED;
        if(playcliked==500){
            playcliked=0;
            stopclicked=0;
            play.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/play/play_1.png")));
            pause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/pausa/pause_2.png")));
            
            t5.run();
        if(r.getPlayer()!=null)
            t4.run();
        }
    }//GEN-LAST:event_pauseMouseClicked

    private void pauseMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMouseEntered
        // TODO add your handling code here:
        if(pauseclicked!=500)
                pause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/pausa/pause_3.png")));

    }//GEN-LAST:event_pauseMouseEntered

    private void pauseMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_pauseMouseExited
        // TODO add your handling code here:
        if(pauseclicked!=500)
                pause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/pausa/pause_1.png")));
    }//GEN-LAST:event_pauseMouseExited

    private void stopMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMouseClicked
        // TODO add your handling code here:
        titulo();
        segundo=0;
        minutos=0;
        horas=0;
        tr.restart();
        tr.stop();
        tiempoReproduccion.setText("00:00:00");
        stopclicked=evt.MOUSE_CLICKED;
        play.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/play/play_1.png")));
        pause.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/pausa/pause_1.png")));
        stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/stop/stop_4.png")));
        t3.run();
        animacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jc/skin/imagenes/disco_1.gif")));

    }//GEN-LAST:event_stopMouseClicked

    private void stopMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMousePressed
        // TODO add your handling code here:
        stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/stop/stop_2.png")));
    }//GEN-LAST:event_stopMousePressed

    private void stopMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMouseEntered
        // TODO add your handling code here:
        if(stopclicked!=500)
            stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/stop/stop_3.png")));
    }//GEN-LAST:event_stopMouseEntered

    private void stopMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_stopMouseExited
        // TODO add your handling code here:
        if(stopclicked!=500)
            stop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/stop/stop_1.png")));
    }//GEN-LAST:event_stopMouseExited

    private void nextMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextMouseEntered
        // TODO add your handling code here:
        next.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/siguiente/next_3.png")));
    }//GEN-LAST:event_nextMouseEntered

    private void nextMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextMouseExited
        // TODO add your handling code here:
        next.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/siguiente/next_1.png")));
    }//GEN-LAST:event_nextMouseExited

    private void nextMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextMousePressed
        // TODO add your handling code here:
        next.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/siguiente/next_2.png")));
    }//GEN-LAST:event_nextMousePressed

    private void nextMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_nextMouseClicked
        // TODO add your handling code here:
        segundo=0;
        minutos=0;
        horas=0;
        tiempoReproduccion.setText("00:00:00");
        next.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/siguiente/next_3.png")));
        if(btnRandom.isSelected())
            fila=fila+1;
        else
            fila=azar(lista_reproduccion.getModel().getRowCount());
        if(lista_reproduccion.getModel().getRowCount()>0)
            lista_reproduccion.setRowSelectionInterval(fila, fila);
        lista_reproduccion.changeSelection(fila, col, false, false);
        lista_reproduccion.requestFocus();
        f=Archivos.buscarDireccion(list,lista_reproduccion.getValueAt(fila, col).toString());
        t3.run();
        t6.run();
        t2.run();
        titulo();
    }//GEN-LAST:event_nextMouseClicked

    private void previusMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_previusMouseClicked
        // TODO add your handling code here:
        segundo=0;
        minutos=0;
        horas=0;
        tiempoReproduccion.setText("00:00:00");
        previus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/previo/previus_3.png")));
        fila=fila-1;
        f=Archivos.buscarDireccion(list,lista_reproduccion.getValueAt(fila, col).toString());
        titulo();
        t3.run();
        t6.run();
        t2.run();
    }//GEN-LAST:event_previusMouseClicked

    private void previusMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_previusMouseEntered
        // TODO add your handling code here:
        previus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/previo/previus_3.png")));
    }//GEN-LAST:event_previusMouseEntered

    private void previusMouseExited(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_previusMouseExited
        // TODO add your handling code here:
        previus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/previo/previus_1.png")));
    }//GEN-LAST:event_previusMouseExited

    private void previusMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_previusMousePressed
        // TODO add your handling code here:
        previus.setIcon(new javax.swing.ImageIcon(getClass().getResource("/JC/skin/componentes/botones/previo/previus_2.png")));
    }//GEN-LAST:event_previusMousePressed

    private void openMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_openMouseClicked
        // TODO add your handling code here:
        archivos.showOpenDialog(this);
            if(archivos.getSelectedFile()!=null){
            list=new Archivos().ficheros(archivos.getSelectedFile(),".mp3");
            String buscar[]=new String[list.size()];
            DefaultTableModel model=(DefaultTableModel) lista_reproduccion.getModel();
            for(int i=0;i<list.size();i++){
                buscar[i]=list.get(i).getName();
            }
            for(int i=0;i<buscar.length;i++){
                String add[]={buscar[i]};
                model.addRow(add);
            }
        }
    }//GEN-LAST:event_openMouseClicked

    private void lista_reproduccionMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_lista_reproduccionMouseClicked
        // TODO add your handling code here:
        if(evt.getClickCount()==2){
            playcliked=500;
            titulo();
            col=lista_reproduccion.columnAtPoint(evt.getPoint());
            fila=lista_reproduccion.rowAtPoint(evt.getPoint());
            f=Archivos.buscarDireccion(list,lista_reproduccion.getValueAt(fila, col).toString());
            if(f!=null){
                if(r.getPlayer()==null){
                    playMouseClicked(evt);
                    t6.run();
                    t2.run();
                }else{
                    t3.run();
                    t6.run();
                    t2.run();
                    playMouseClicked(evt);
                }
                
            }
            if(r.getPlayer()!=null){
                Tiempo tiempo=new Tiempo(r);
                listo=tiempo.getTimer();
                listo.start();
            }
        }
    }//GEN-LAST:event_lista_reproduccionMouseClicked

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        JFrame.setDefaultLookAndFeelDecorated(true);
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
                try {
                  //SubstanceLookAndFeel.setSkin(new BusinessBlackSteelSkin());
                    //configuracion de una apariencia
                        SubstanceLookAndFeel.setSkin(new ChallengerDeepSkin());
                } catch (Exception e) {
                  System.out.println("Substance Graphite failed to initialize");
                }
                JCFrameReproductor reproductor= new JCFrameReproductor();
                reproductor.setVisible(true);
          }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel animacion;
    private javax.swing.JFileChooser archivos;
    private javax.swing.JToggleButton btnRandom;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JTable lista_reproduccion;
    private javax.swing.JLabel next;
    private javax.swing.JLabel open;
    private javax.swing.JPanel panel1;
    private javax.swing.JLabel pause;
    private javax.swing.JLabel play;
    private javax.swing.JLabel previus;
    private javax.swing.JSlider progreso;
    private javax.swing.JLabel stop;
    private javax.swing.JLabel tiempoReproduccion;
    // End of variables declaration//GEN-END:variables

    private void animacion(){
        animacion.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jc/skin/animaciones/discogif.gif")));
    }

    private int azar() {
        Random random= new Random();
        
        int numero=random.nextInt(6)+1;
        if(numero<2||numero>6)
            azar();
        return numero;
    }
    private int azar(int num) {
        Random random= new Random();

        int numero=random.nextInt(num)+1;
        if(numero>num)
            azar();
        return numero;
    }

    private String cambiar(String name) {
        String nominv=name;
        char c='\\';
        char []carateres=name.toCharArray();
        for(int i =0;i<nominv.length();i++){
            if(carateres[i]==c){
                carateres[i]='/';
            }
        }
        for(int i=0;i<carateres.length;i++){
            if(i==0)
                nominv=Character.toString(carateres[i]);
            else
                nominv=nominv+Character.toString(carateres[i]);
        }
        
        
        return nominv;
    }

    private void titulo() {
        if(f!=null)
            setTitle(f.getName());
    }

    public synchronized  void controllerUpdate(ControllerEvent event) {
        progreso.setMaximum((int) event.getSourceController().getDuration().getSeconds());
        progreso.setValue((int) event.getSourceController().getMediaTime().getSeconds());
    }

    public void nextTo(){
        titulo();
        segundo=0;
        minutos=0;
        horas=0;
        tiempoReproduccion.setText("00:00:00");
        tr.restart();
            fila=fila+1;
            f=Archivos.buscarDireccion(list,lista_reproduccion.getValueAt(fila, col).toString());
            if(f!=null){
                if(r.getPlayer()==null){
                    playMouseClicked(null);
                    t6.run();
                    t2.run();
                }else{
                    t3.run();
                    t6.run();
                    t2.run();
                    playMouseClicked(null);
                }

            }
            if(r.getPlayer()!=null){
                Tiempo tiempo=new Tiempo(r);
                listo=tiempo.getTimer();
                listo.start();
            }
    }
    public void listo(){
        listo=new Timer (1000, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                r.controllerUpdate(null);
            }
        });
    }
    public String digito(int numero){
        int aux=numero;
        int digito=0;
        String num="";
        if(aux==0){
            num= "00";
        }else{
            while ( numero > 0 ) {
                numero /=10;
                digito++;
            }
            if(digito==1)
                num= "0"+aux;
            else
                num=String.valueOf(aux);
        }
        return num;
    }
    
}
